﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using WcfiMathService.Models;

namespace WcfiMathService.Mappers
{
    public static class Mapper
    {
        public static ExamView ExamToView(Exam exam)
        {
            if (exam == null) return null;
            return new ExamView() { Id = exam.Id, Name = exam.Name, Description = exam.Description, CreateDate = exam.CreateDate, CreateBy = exam.CreateBy, StartDate = exam.StartDate, EndDate = exam.EndDate };
        }

        public static List<ExamView> ExamsToView(List<Exam> exams)
        {
            List<ExamView> _list = new List<ExamView>();
            foreach(Exam _exam in exams)
            {
                if(_exam != null)                
                    _list.Add(ExamToView(_exam));
            }
            return _list;
        }
        public static QuestionView QuestionToView(Question question)
        {
            if (question == null) return null;
            return new QuestionView() 
            {
                Id = question.Id,
                Title = question.Title,
                Content = question.Content,
                CreateBy = question.CreateBy,
                CreateDate = question.CreateDate                
            };
        }

        public static AnswerView AnswerToView(Answer answer)
        {
            if (answer == null) return null;
            return new AnswerView()
            {
                Id = answer.Id,
                Content = answer.Content,
                CreateBy = answer.CreateBy,
                CreateDate = answer.CreateDate,
                QuestionId = answer.QuestionId,
            };
        }

        public static UserExamView UserExamToView(UserExam uExam)
        {
            if (uExam == null) return null;
            return new UserExamView()
            {
                UserName=uExam.UserName,
                ExamId=uExam.ExamId,
                StartDate=uExam.StartDate,
                EndDate=uExam.EndDate,
                CorrectAnswers=uExam.CorrectAnswers,
                TotalMark=uExam.TotalMark
            };
        }

        public static List<UserExamView> UserExamToView(List<UserExam> uExams)
        {
            List<UserExamView> _list = new List<UserExamView>();
            foreach (UserExam _userexam in uExams)
            {
                if (_userexam != null)
                    _list.Add(UserExamToView(_userexam));
            }
            return _list;
        }

        public static List<QuestionView> QuestionsToView(List<Question> questions)
        {
            List<QuestionView> _list = new List<QuestionView>();
            foreach (Question _q in questions)
            {
                if (_q != null)
                    _list.Add(QuestionToView(_q));
            }
            return _list;
        }
    }
}